package com.zhuqi.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.img.ImgUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhuqi
 * @version 1.0
 * @date 2021/3/26 8:53
 * 二维码生产的controller
 */
@Controller
public class CodeController {

    @ResponseBody
    @RequestMapping("/code")
    public void codeMsg(HttpServletRequest request, HttpServletResponse response) throws IOException {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100, 1, 10);
        request.getSession().setAttribute("error",lineCaptcha);
        ImgUtil.write(lineCaptcha.getImage(), "JPEG", response.getOutputStream());
    }

}
